<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, target-densitydpi=device-dpi"
          name="viewport">
    <link rel="stylesheet" type="text/css" href="/js/plugins/qianbao/reset.css">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/register.css">
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="js/plugins/dialog2/dialog.css">
    <link rel="stylesheet" type="text/css" href="/js/plugins/qianbao/weichat.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/jquery-validation/jquery.validate.min.js"></script>
    <script src="/js/plugins/jquery-validation/messages/messages_cn.js"></script>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <title>My Wallet</title>
    <script>
        $(function () {
            $(document).on('click', '#btn-11', function () {
                $(document).dialog({
                    type: 'toast',
                    infoIcon: '../images/icon/loading.gif',
                    infoText: '正在加载中',
                    autoClose: 2500
                });
            });
            //余额回显
            var user = JSON.parse(sessionStorage.getItem('user'));
            console.log(user);
            var userId = user.id;
            $.get("/mymoneys/" + userId, function (data) {
                console.log(data.money);
                $(".kyye").html("当前零钱余额" + data.money + "元");
            })
            $("#getout").click(function () {
                var rmb = $("#getmoneys").val();

                //console.log(rmb);
                $.ajax({
                    url: "/mymoneys/addmoneys/" + userId,
                    type: "put",
                    data: {rmb: rmb},
                    success: function (data) {
                        window.location.href = "/qianbao_index.html"
                    }

                })

            })


        })
    </script>

</head>
<body>
<div class="wrap">
    <div class="top-bar">
        <div class="goback"><a href="wallet_tixian.html"><img
                src="http://www.17sucai.com/preview/1202/2018-08-12/wallet/img/fh.png"></a></div>
        <h1>零钱充值</h1>
        <div class="wallet-more">.....</div>
    </div>
    <div class="tixian-box">
        <div class="tobank">
            <span class="dzyh">到帐银行卡</span>
            <span class="yhk">建设银行(8888)</span>
            <span class="dz">2小时内到帐</span>
        </div>
        <div class="t-moneys">
            <span class="txje">充值金额</span>
            <span class="rmb">￥</span>
            <span class="kyye">当前零钱余额：25546.60元，<a href="javascript:;" id="getall">全部充值</a></span>
            <input type="text" id="getmoneys" class="t-input">
            <button id="getout">充值</button>
        </div>
    </div>
</div>
<script>
    window.onload = function () {
        var okyMOneys = 25546.6;//模拟可用余额,实际使用的时候从数据库返回或其它的操作。
        var oGetAll = document.getElementById("getall");
        var oGetMoneys = document.getElementById("getmoneys");
        var oGetOut = document.getElementById("getout");
        var oKyye = document.getElementsByClassName("kyye")[0];


        oGetMoneys.oninput = function ()//监听用户的输入给出相应提示。
        {
            if (oGetMoneys.value == "") {
                oGetOut.style.opacity = 0.4;
                oKyye.innerHTML = "当前零钱余额：25546.60元，<a href='javascript:;'' id='getall'>全部提现</a>"
            }
            else if (parseFloat(oGetMoneys.value) > okyMOneys) {
                oGetOut.style.opacity = 0.4;
                oKyye.innerHTML = "<font color=red>输入金额超过零钱余额</font>"
            }
            else {
                var paroGetMoneys = parseFloat(oGetMoneys.value);
                var sxf = paroGetMoneys * 0.001;
                var sjdz = paroGetMoneys - sxf;
                //oGetMoneys.value=sjdz.toFixed(2);
                oKyye.innerHTML = "额外扣除￥" + sxf.toFixed(2) + "手续费（费率0.1%）";
                oGetOut.style.opacity = 1;
                //这里就可以进行与后台交互的操作比如ajax操作等。
            }
        };


        //全部提现
        oGetAll.onclick = function () {
            var parGetMoneys = parseFloat(oGetMoneys.value);//格式化成数字
            var sjdz = okyMOneys - (okyMOneys * 0.001);//手费0.1%
            var sxf = okyMOneys * 0.001;
            oGetMoneys.value = sjdz.toFixed(2);
            oKyye.innerHTML = "额外扣除￥" + sxf.toFixed(2) + "手续费（费率0.1%）";
            //alert("a");
        };
    };
</script>
</body>
</html>